package com.example.labyrinth;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class LabyrinthSolver {

    public static void main(String[] args) throws IOException {
        List<List<Character>> labyrinth = readLabyrinthFromFile(new FileInputStream("labyrinth.txt"));

        PathToCheeseFinder pathToCheeseFinder = new PathToCheeseFinder(labyrinth);
        cheesefinder cheesefinder = new cheesefinder();
        String path = pathToCheeseFinder.findPathToCheese();

        printLabyrinth(labyrinth);
        printPath(path);
    }

    private static void printPath(String path) {
        System.out.println(path);
    }

    public static List<List<Character>> readLabyrinthFromFile(InputStream inputStream) throws IOException {
        List<List<Character>> labyrinth = new ArrayList<>();

        try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
            String lineString;
            while ((lineString = bufferedReader.readLine()) != null) {
                List<Character> line = new ArrayList<>();
                for (int i = 0; i < lineString.length(); i++) {
                    line.add(lineString.charAt(i));
                }
                labyrinth.add(line);
            }
        }

        return labyrinth;
    }

    private static void printLabyrinth(List<List<Character>> labyrinth) {
        for (List<Character> line: labyrinth) {
            for (Character character: line) {
                System.out.print(character);
            }
            System.out.println();
        }
    }
}
